/*(function(doc, win) {
    var docEl = doc.documentElement,
        resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
        recalc = function() {
            var clientWidth = docEl.clientWidth;
            if (!clientWidth) return;
            docEl.style.fontSize = 20 * (clientWidth / 375) + 'px';
        };
    if (!doc.addEventListener) return;
    win.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);*/
import Vue from 'vue'


//去空格
Vue.prototype.trimStr = function (str){
    return str.replace(/(^\s*)|(\s*$)/g,"")
};

//加密方法
Vue.prototype.jsEncrypt = function (str){
    let arr = str.split('');
    let passToken = "";
    for(var i=0;i<arr.length;i++){
      passToken += arr[i].charCodeAt();
      passToken += "/";
    }
    let lastToken=passToken.substring(0,passToken.length-1)
    return lastToken
};

//解密方法
Vue.prototype.jsDecrypt = function (str){
    let miwen = '';
    let arr = str.split("/");
    for(let i in arr){
      miwen += String.fromCharCode(arr[i]);
    }
    return miwen
};


//检查token
Vue.prototype.Check = function (){
      var admin='';
      var name = "admin" + "=";
      var ca = document.cookie.split(';');
      for (var i = 0; i < ca.length; i++) {
          var c = ca[i].split("=");
          if(this.trimStr(c[0])=="admin"){
              admin=c[1];
          }
      };
      if(admin!=''){
        this.$store.dispatch("tokensync",this.jsDecrypt(admin));
        return true
      }else{
        this.$store.dispatch("tokensyncTo");
      };
};


//检查是否为空
Vue.prototype.Input = (val) => {
  if(val.length==0){
    return false
  }else{
    return true
  }
}

//检查是否为邮箱
Vue.prototype.InputEmail = (val) => {
  let reg=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
  return reg.test(val)
}

//检查是否为手机
Vue.prototype.InputTel = (val) => {
  let reg=/^1(3|4|5|7|8)\d{9}$/;
  return reg.test(val)
}

